﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ShadowCommando.Game.Utilites;
using System.Configuration;
namespace ShadowCommando.Game.Elements.Bonus
{
    /// <summary>
    /// Klasa reprezentująca bonus
    /// </summary>
  public  class Bonus:Element
    {
      /// <summary>
      /// Konstrukroe
      /// </summary>
      /// <param name="_step">Krok</param>
      /// <param name="_difficulty">Poziom trudności</param>
      /// <param name="id">Id pocisku</param>
        public Bonus(int _step,LevelDifficulty _difficulty,BonusId id):base(_step,_difficulty)
        {
            elementId = ElementId.Bonus;
            Shootable = true;
            Movable = true;
            bonusId = id;
            CreateBonus(bonusId);
            zIndex = -1;
        }
        #region Items

        private BonusId bonusId;
        private int bonus;
        #endregion
        #region Properties
      /// <summary>
      /// Bonus Id
      /// </summary>
      public BonusId BonusID
      {
          get { return bonusId; }
          set { bonusId = value; }
      }
        #endregion
        private void CreateBonus(BonusId id)
        {
            switch(id)
            {
                case BonusId.MedicalKit:
                    {
                        LoadSettings(MedicalKitInfo.Default);
                        break;
                    }
                case BonusId.Armor:
                    {
                        LoadSettings(ArmorInfo.Default);
                        break;
                    }
                case BonusId.Ammuntion:
                    {
                        LoadSettings(AmmoInfo.Default);
                        
                        break;
                    }
            }
        }
        private void LoadSettings(ApplicationSettingsBase asb)
        {
            bonus = (int) asb["Bonus"];
        }
        /// <summary>
        /// Daje bonus w zalezności od rodzaju
        /// </summary>
        /// <param name="character">Postać która ma otrzymać bonus</param>
        public void GiveBonus(Character character)
        {
            switch (bonusId)
            {
                case BonusId.Ammuntion:
                    {
                        Random rnd = new Random();
                        int number = rnd.Next(character.Weapons.Count);
                        while (character.Weapons[number].BulletId == BulletId.Bomb || character.Weapons[number].BulletId == BulletId.Laser)
                            number = rnd.Next(character.Weapons.Count);
                        character.Weapons[number].BulletCount += bonus;
                        if (character.Weapons[number].BulletCount > character.Weapons[number].MaxBullet)
                            character.Weapons[number].BulletCount = character.Weapons[number].MaxBullet;
                        break;
                    }
                case BonusId.Armor:
                    {
                        character.Armor += bonus;
                        if(character.Armor>character.MaxArmor)
                            character.Armor = character.MaxArmor;
                        break;
                    }
                case BonusId.MedicalKit:
                    {
                        character.Life += bonus;
                        if(character.Life>character.MaxLife)
                            character.Life = character.MaxLife;
                        break;
                    }

            }
        }
    }
}
